/*
 * 标签
 */

import { createAPI } from '@/utils/request'
// 引入moment
import moment from 'moment'

// 标签列表
export const list = data => createAPI('/tags', 'get', data)
  .then(res => ({
    items: res.data.items.map((d, i) => ({
      ...d,
      index: i + 1,
      state: d.state === 1 ? '已启用' : '已禁用',
      addDate: moment(d.addDate).format('YYYY-MM-DD HH:mm:ss'),
    })),
    counts: res.data.counts
  }))
  .catch(err => err)


// 标签简单列表
export const simple = data => createAPI('/tags/simple', 'get', data)

// 标签详情
export const detail = data => createAPI(`/tags/${data.id}`, 'get', data)

// 标签添加
export const add = data => createAPI('/tags', 'post', data)

// 标签修改
export const update = data => createAPI(`/tags/${data.id}`, 'put', data)

// 标签删除
export const remove = data => createAPI(`/tags/${data.id}`, 'delete', data)

// 标签状态
export const changeState = data => createAPI(`/tags/${data.id}/${data.state}`, 'post', data)
